var util = require('../../../utils/util.js');
var api = require('../../../config/api.js');
var user = require('../../../utils/user.js');
const app = getApp()
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
Page({
    data: {
        userInfo: {}
    },
    onLoad() {
        let userInfo = wx.getStorageSync('userInfo');
        if (userInfo.avatarUrl) {
            this.setData({
                userInfo: userInfo,
            });
        }
    },
    binkVlue(e) {
        let data = this.data.userInfo
        data.nickName = e.detail.value
        this.setData({
            userInfo: data
        })
    },
    chooseavatar(e) {
        console.log(e, '头像')
        const { avatarUrl } = e.detail
        let host = this.data.userInfo
        host.avatarUrl = avatarUrl
        this.setData({
            userInfo: host
        })
    },
    postUp() {
        let hostUs = this.data.userInfo
        let userInfo = wx.getStorageSync('userInfo')
        console.log(userInfo)
        let data = {
            avatarUrl: hostUs.avatarUrl,
            nickName: hostUs.nickName,
            userId: userInfo.userId
        }
        util.request(api.updateUsinfo, data, 'POST').then(function (res) {
            console.log(res)
            if (res.errno == 0) {
                wx.setStorageSync('userInfo', data)
                wx.navigateBack({
                    delta: 1
                })
            }
        })
    }
})
